import { IFeidaoAiNodejsComponent } from '@feidao/web/interfaces';

import render from '@feidao/web/atom/nodejs/render/render';
import get_menus from '@feidao/web/atom/nodejs/authorization/get-menus';
////////////////////////////////////////////////////////////////////////////////
// import presentations
////////////////////////////////////////////////////////////////////////////////

export default async function na001(fd: IFeidaoAiNodejsComponent, ...args: any[]) {

	// 数据结构
	const data = await get_menus(fd.data.msg, fd.data.headers);
	// 数据处理
	// console.warn(data);
	const t = (p: any) => {
		return data.filter((d: any) => {
			return d.parent_no == p;
		});
	}
	const d1 = data.filter((d: any) => {
		d.c = t(d.menu_no);
		return d.parent_no == '';
	});

	let r = ``;
	const t1 = (data: any, level: number) => {
		data.forEach((d: any) => {
			//  data=` + encodeURIComponent(JSON.stringify(d)) + `
			// const bc = d.color ? 'background-color: ' + d.color + ';' : '';
			if (d.c.length == 0) {
				let str = ``;
				str = `<div name="div` + level + `" class="menu` + level + `" style="display: none;">
					<div name="xz" class="bg" flag="0" data-feidao-l="` + level + `" data-feidao-actions="click:eu-001,mouseout:eu-002,mouseover:eu-003">
					<a href="`+ (d.package_url ? d.package_url : 'javascript:void(0)') + `">
						<div class="opacity" style="height: 44px;width: 100%;">
							<i class="child_icon iconfont `+ d.icon + `" style="width: 44px;height:44px;line-height:44px;float: left;"></i>
							<span class="menu` + level + `_name" style="height: 44px;line-height: 44px;">` + d.menu_name + `</span>
						</div>
						</a>
					</div>
				</div>`;
				r += str;
			} else {
				let str = ``;
				str = `<div name="div` + level + `" class="menu` + level + `" style="display: none;">
					<div name="xz" class="bg" flag="0" data-feidao-l="` + level + `" data-feidao-actions="click:eu-001,mouseout:eu-002,mouseover:eu-003">
					<a href="`+ (d.package_url ? d.package_url : 'javascript:void(0)') + `">
						<div class="opacity" style="height: 44px;width: 100%;">
							<i class="child_icon iconfont `+ d.icon + `" style="width: 44px;height:44px;float: left;"></i>
							<span class="menu` + level + `_name" style="height: 44px;line-height: 44px;">` + d.menu_name + `</span>
						</div></a>
					</div><div data-feidao-level="`+ (level + 1) + `">`;
				r += str;
				t1(d.c, (level + 1));
			}
		});
		r += `</div></div>`;
	}

	// 第一级目录
	d1.forEach((d: any) => {
		const bc = d.background ? 'background: ' + d.background + ';' : '';
		//  data=` + encodeURIComponent(JSON.stringify(d)) + `
		if (d.c.length == 0) {
			r += `<div data-feidao-level="1">
				<div class="menu1 bg" style="height:44px;line-height: 44px;" flag="0" data-feidao-l="1" data-feidao-actions="click:eu-001,mouseout:eu-002,mouseover:eu-003">
				<a href="`+ (d.package_url ? d.package_url : 'javascript:void(0)') + `">
				<span class="left_icon" style="width: 44px;height:44px;">
					<i class="iconfont icon `+ d.icon + `" style="width: 44px;height:44px;"></i>
					<span class="color" style="left: -44px;width: 44px;height:44px;position: absolute;`+ bc + `" data-feidao-s="s"></span>
				</span>
				<span class="menu_name" style="width: 124px;height: 44px;">`+ d.menu_name + `</span>
				<i class="flod_icon" style="line-height: 44px;right: 15px;margin-top: -10px;"></i></a>
		</div>`;
		} else {
			r += `<div data-feidao-level="1">
				<div class="menu1 bg" style="height:44px;line-height: 44px;" flag="0" data-feidao-l="1" data-feidao-actions="click:eu-001,mouseout:eu-002,mouseover:eu-003">
				<a href="`+ (d.package_url ? d.package_url : 'javascript:void(0)') + `">
				<span class="left_icon" style="width: 44px;height:44px;">
					<i class="iconfont icon `+ d.icon + `" style="width: 44px;height:44px;"></i>
					<span class="color" style="left: -44px;width: 44px;height:44px;position: absolute;`+ bc + `" data-feidao-s="s"></span>
				</span>
				<span class="menu_name" style="width: 124px;height: 44px;">`+ d.menu_name + `</span>
				<i class="flod_icon" style="line-height: 44px;right: 15px;margin-top: -10px;"><img data-feidao-id="icon" style="margin-top: 20px;display: inline-block;" src="./images/jt_button.png"></i></a>
		</div><div data-feidao-level="2">`;
			t1(d.c, 2);
		}
		r += '</div>';
	});

	render(fd.data.node, '', r, 'P01');
}
